public class LeetCode11 {
    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int l = 0, r = height.length - 1;
        int res = 0;
        int area = 0;
        int len = height.length;
        while (len-- > 0) {
            int leftValue = height[l], rightValue = height[r];//优化加载速度
            if (leftValue < rightValue) {
                area = leftValue * len;
                if (res < area) {
                    res = area;
                }
//                res = Math.max(res,area); 耗时多1ms 弃用
                l++;
            } else {
                area = rightValue * len;
                if (res < area) {
                    res = area;
                }
//                res = Math.max(res,area); 耗时多1ms 弃用
                r--;
            }
        }
        return res;
    }
}
